package com.linked.gateway.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author :dbq
 * @date : 2023/7/31 9:01
 * @description :
 * Jackson with JSON: Unrecognized field, not marked as ignorable
 * 原因是前台发送的数据中，部分字段在后台POJO中没有定义。SpringMVC使用了ObjectMapper对数据进行转换，
 * 但ObjectMapper默认配置会检查对应的字段是否存在，如果不存在就会报错。解决方法有两种：
 * 另外一种：在POJO对象中加入@JsonIgnoreProperties(ignoreUnknown = true)。
 */
@Configuration
public class ObjectMapperConfiguration {
    @Bean
    public ObjectMapper mapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return mapper;
    }
}
